home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-09-17 | 15.3 KB | 517 lines | [TEXT/CWIE] |
- //========================================================================================
- //
- // File: View.cpp
- // Release Version: $ ODF 2 $
- //
- // Copyright: (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
- //
- //========================================================================================
-
- #ifndef VIEW_H
- #include "View.h"
- #endif
-
- #ifndef FRAME_H
- #include "Frame.h"
- #endif
-
- #ifndef CONTENT_H
- #include "Content.h"
- #endif
-
- #ifndef TRACKER_H
- #include "Tracker.h"
- #endif
-
- #ifndef LINKING_H
- #include "Linking.h"
- #endif
-
- #ifndef SELECTION_H
- #include "Selection.h"
- #endif
-
- #ifndef FWCONTXT_H
- #include "FWContxt.h"
- #endif
-
- #ifndef FWITERS_H
- #include "FWIters.h"
- #endif
-
- #ifndef FWLNKITE_H
- #include "FWLnkIte.h"
- #endif
-
- #ifndef FWFCTCLP_H
- #include "FWFctClp.h"
- #endif
-
- #ifndef FWODMISC_H
- #include "FWODMisc.h"
- #endif
-
- #ifndef FWRGNSHP_H
- #include "FWRgnShp.h"
- #endif
-
- #ifndef FWTOOLBX_H
- #include "FWToolBx.h"
- #endif
-
- #ifndef FWMNUBAR_H
- #include "FWMnubar.h"
- #endif
-
- //========================================================================================
- // RunTime Info
- //========================================================================================
-
- FW_DEFINE_CLASS_M1(CTableView, FW_CSuperView)
-
- const FW_ClassTypeConstant LTableView = FW_TYPE_CONSTANT('t','b','v','w');
- FW_REGISTER_ARCHIVABLE_CLASS(LTableView, CTableView, CTableView::Create, FW_CView::Read, CTableView::Destroy, FW_CView::Write)
-
- //========================================================================================
- // class CTableView
- //========================================================================================
-
- //----------------------------------------------------------------------------------------
- // CTableView::CTableView
- //----------------------------------------------------------------------------------------
-
- CTableView::CTableView(Environment* ev) :
- FW_CSuperView(ev),
- fTablePart(NULL),
- fTableFrame(NULL),
- fTableContent(NULL),
- fGridShown(TRUE),
- fHighlight(kODNoHighlight)
- {
- }
-
- //----------------------------------------------------------------------------------------
- // CTableView::~CTableView
- //----------------------------------------------------------------------------------------
-
- CTableView::~CTableView()
- {
- }
-
- //----------------------------------------------------------------------------------------
- // CTableView::Draw
- //----------------------------------------------------------------------------------------
-
- void CTableView::Draw(Environment* ev, ODFacet* odFacet, ODShape* invalidShape)
- {
- FW_CViewContext fc(ev, this, odFacet, invalidShape);
-
- FW_CRect invalidRect;
- fc.GetClipRect(invalidRect);
-
- // Erase invalid portion of the frame
- FW_CRectShape::RenderRect(fc, invalidRect, FW_kFill, FW_kWhiteEraseInk);
-
- DrawGray(ev, fc);
-
- // Draw the table grid
- if (fGridShown)
- DrawGrid(ev, fc, TRUE);
-
- // Draw the selection
- if (fTableFrame->HasSelectionFocus(ev) && fGridShown && (fHighlight == kODFullHighlight))
- DrawCellHighlight(ev, fc, fTableFrame->GetSelection(ev)->GetSelectedCell());
-
- //--- Draw Link borders ---
- FW_CAcquiredODWindow aqODWindow = odFacet->GetFrame(ev)->AcquireWindow(ev);
- if (aqODWindow->ShouldShowLinks(ev))
- {
- //--- Draw borders around links ---
- FW_CLinkIterator it(fTablePart->GetLinkManager(ev));
- for (FW_CLink* link = it.FirstLink(); it.IsNotComplete(); link = it.NextLink())
- {
- link->ShowHideLinkBorder(ev, true, odFacet);
- }
- }
- }
-
- //----------------------------------------------------------------------------------------
- // CTableView::DrawGray
- //----------------------------------------------------------------------------------------
-
- void CTableView::DrawGray(Environment* ev, FW_CGraphicContext& gc)
- {
- FW_CRect contentRect = GetBoundsInContent(ev);
- FW_CRect extentRect(FW_kZeroPoint, fTableContent->GetExtent());
-
- FW_CAcquiredODShape shape1 = ::FW_NewODShape(ev, contentRect);
- FW_CAcquiredODShape shape2 = ::FW_NewODShape(ev, extentRect);
- shape1->Subtract(ev, shape2);
- if (!shape1->IsEmpty(ev))
- {
- FW_CRegionShape::RenderRegion(gc, shape1, FW_kFill, FW_kRGBLightGray);
-
- extentRect.Inset(FW_kFixedNeg1, FW_kFixedNeg1);
- FW_CRectShape::RenderRect(gc, extentRect, FW_kFrame);
- }
- }
-
- //----------------------------------------------------------------------------------------
- // CTableView::DrawCellHighlight
- //----------------------------------------------------------------------------------------
-
- void CTableView::DrawCellHighlight(Environment* ev, FW_CViewContext& fc, const CCell& cell)
- {
- CTableProxy* proxy = fTableContent->CellToProxy(cell);
- if (proxy == NULL)
- {
- FW_CRect rect;
- fTableContent->FindRect(cell, rect);
- FW_CRectShape::RenderRect(fc, rect, FW_kFill, FW_CInk(FW_kSystemHilite));
- }
- else
- {
- FW_CAcquiredODShape hiliteShape = proxy->AcquireHiliteShape(ev, cell, fTableFrame);
- FW_CRegionShape::RenderRegion(fc, hiliteShape, FW_kFill, FW_CInk(FW_kSystemHilite));
- }
- }
-
- //---------------------------------------------------------------------------------------
- // CTableView::DrawGrid
- //---------------------------------------------------------------------------------------
-
- void CTableView::DrawGrid(Environment* ev, FW_CGraphicContext& gc, FW_Boolean gray)
- {
- FW_UNUSED(ev);
- // Get the frame's rect at (0,0)
- FW_CRect rect(FW_kZeroPoint, fTableContent->GetExtent());
-
- // Draw the table grid
- FW_CLineShape lineShape;
- lineShape.GetStyle().SetPattern(gray ? FW_kGrayPat : FW_kWhitePat);
-
- FW_Fixed xy;
- short rc;
- for(xy = rect.top, rc = 0; xy < rect.bottom; xy += fTableContent->GetHeight(rc++) + kBorderHeight)
- {
- lineShape.SetLineStart(rect.left, xy);
- lineShape.SetLineEnd(rect.right - FW_kFixedPos1, xy);
- lineShape.Render(gc);
- }
-
- for(xy = rect.left, rc = 0; xy < rect.right; xy += fTableContent->GetWidth(rc++) + kBorderHeight)
- {
- lineShape.SetLineStart(xy, rect.top);
- lineShape.SetLineEnd(xy, rect.bottom - FW_kFixedPos1);
- lineShape.Render(gc);
- }
- }
-
- //----------------------------------------------------------------------------------------
- // CTableView::DoMouseDown
- //----------------------------------------------------------------------------------------
-
- FW_Handled CTableView::DoMouseDown(Environment* ev, const FW_CMouseEvent& theMouseEvent)
- {
- FW_Handled result = FW_kNotHandled;
-
- if (fGridShown)
- {
- if (fTableFrame->GetSelection(ev)->IsMouseInDraggableItem(ev, fTableFrame, theMouseEvent, FALSE) &&
- fTableFrame->Drag(ev, theMouseEvent))
- {
- result = FW_kHandled;
- }
- else
- {
- CCell cell;
- ETableLoc tl = fTableContent->HitTest(ev, theMouseEvent, this, cell);
-
- if (tl != kTLNone && tl != kTLCell)
- this->Resize(ev, theMouseEvent, cell, tl);
-
- result = FW_kHandled;
- }
- }
-
- return result;
- }
-
- //----------------------------------------------------------------------------------------
- // CTableView::AdjustCursor
- //----------------------------------------------------------------------------------------
- // Where is in Frame coordinate
- FW_Handled CTableView::AdjustCursor(Environment* ev, ODFacet* odFacet, const FW_CPoint& where, ODEventInfo* eventInfo)
- {
- FW_Handled cursorAdjusted = FW_kNotHandled;
-
- // I don't want the Open Hand Cursor if I have the grid hidden because I am not supposed to
- // be able to move anything
- if (fGridShown)
- cursorAdjusted = FW_CSuperView::AdjustCursor(ev, odFacet, where, eventInfo);
-
- if (!cursorAdjusted && fGridShown)
- {
- CCell cell;
- FW_CPoint temp(where);
- FrameToViewContent(ev, temp);
- ETableLoc tl = fTableContent->HitTest(ev, temp, cell);
-
- cursorAdjusted = FW_kHandled;
-
- if (tl == kTLCell || tl == kTLNone)
- FW_gArrowCursor.Select();
- else if (tl == kTLLeftBorder || tl == kTLRightBorder)
- FW_gSizeWECursor.Select();
- else if (tl == kTLTopBorder || tl == kTLBottomBorder)
- FW_gSizeNSCursor.Select();
- else
- FW_gSizeNWSECursor.Select();
- }
-
- return cursorAdjusted;
- }
-
- //----------------------------------------------------------------------------------------
- // CTableView::Resize
- //----------------------------------------------------------------------------------------
-
- FW_Boolean CTableView::Resize(Environment* ev,
- const FW_CMouseEvent& theMouseEvent,
- const CCell& cell,
- ETableLoc tl)
- {
- FW_ASSERT(tl != kTLNone && tl != kTLCell);
- FW_Boolean result = FALSE;
-
- // maximum rectangle
- FW_CRect maxRect(FW_kZeroPoint, fTableContent->GetExtent());
- maxRect.right -= kPenWidth;
- maxRect.bottom -= kPenHeight;
-
- // Location of borders
- FW_CRect cellRect;
- fTableContent->FindRect(cell, cellRect);
-
- FW_CPoint borders;
- if ((tl & kTLLeftBorder) != 0)
- {
- maxRect.left = ((cell.fX == 0) ? cellRect.left : fTableContent->FindLeft(cell.fX - 1)) + kBorderWidth;
- borders.x = cellRect.left;
- }
- else
- {
- maxRect.left = cellRect.left + kBorderWidth;
- borders.x = cellRect.right;
- }
-
- if ((tl & kTLTopBorder) != 0)
- {
- maxRect.top = ((cell.fY == 0) ? cellRect.top : fTableContent->FindTop(cell.fY - 1)) + kBorderHeight;
- borders.y = cellRect.top;
- }
- else
- {
- maxRect.top = cellRect.top + kBorderHeight;
- borders.y = cellRect.bottom;
- }
-
-
- // Create a tracker for the grid lines
- CGridLineTracker tracker(ev, this, theMouseEvent.GetFacet(ev), tl, maxRect, borders);
-
- if (tracker.Track(ev, theMouseEvent))
- {
- // Set the new cell size
- FW_CPoint delta = tracker.GetNewBorders() - tracker.GetOldBorders();
- if (delta.x != FW_kFixed0 || delta.y != FW_kFixed0)
- {
- fTableContent->Resize(ev, cell, tl, delta);
- fTableFrame->GetPresentation(ev)->Invalidate(ev);
- result = TRUE;
- }
- }
-
- return result;
- }
-
- //----------------------------------------------------------------------------------------
- // CTableView::Create
- //----------------------------------------------------------------------------------------
-
- void* CTableView::Create(FW_CReadableStream& stream, FW_ClassTypeConstant type)
- {
- FW_UNUSED(stream);
- FW_UNUSED(type);
-
- FW_SOMEnvironment ev;
- return new CTableView(ev);
- }
-
- //----------------------------------------------------------------------------------------
- // CTableView::Destroy
- //----------------------------------------------------------------------------------------
-
- void CTableView::Destroy(void* object, FW_ClassTypeConstant type)
- {
- FW_UNUSED(type);
-
- CTableView* self = (CTableView*) object;
- delete self;
- }
-
- //----------------------------------------------------------------------------------------
- // CTableView::DoActivateEvent
- //----------------------------------------------------------------------------------------
-
- void CTableView::DoActivateEvent(Environment* ev, const FW_CActivateEvent& theActivateEvent)
- {
- if (fTableFrame->HasSelectionFocus(ev))
- ChangeHighlightState(ev, theActivateEvent.IsActivating(ev) ? kODFullHighlight : kODDimHighlight);
- }
-
- //----------------------------------------------------------------------------------------
- // CTableView::ChangeHighlightState
- //----------------------------------------------------------------------------------------
-
- void CTableView::ChangeHighlightState(Environment* ev, ODHighlight highlight)
- {
- if (!fGridShown)
- highlight = kODNoHighlight;
-
- if (highlight == fHighlight)
- return;
-
- CCell cell = fTableFrame->GetSelection(ev)->GetSelectedCell();
-
- if (((fHighlight == kODNoHighlight || fHighlight == kODDimHighlight) && (highlight == kODFullHighlight)) ||
- (highlight == kODNoHighlight || highlight == kODDimHighlight) && (fHighlight == kODFullHighlight))
- {
- FW_CFrameFacetIterator ite(ev, fTableFrame);
- for (ODFacet* facet = ite.First(ev); ite.IsNotComplete(ev); facet = ite.Next(ev))
- {
- FW_CViewContext fc(ev, this, facet);
- DrawCellHighlight(ev, fc, cell);
- }
- }
-
- fHighlight = highlight;
-
- CTableProxy* proxy = fTableContent->CellToProxy(cell);
- if (proxy)
- proxy->ChangeHighlight(ev, fHighlight, fTableFrame);
- }
-
- //----------------------------------------------------------------------------------------
- // CTableView::HideShowGrid
- //----------------------------------------------------------------------------------------
-
- void CTableView::HideShowGrid(Environment* ev)
- {
- fGridShown = !fGridShown;
- fTableFrame->ChangeDroppableState(ev, fGridShown ? FW_kFrameDroppable : FW_kNotDroppable);
-
- FW_CFrameFacetIterator ite(ev, fTableFrame);
- for (ODFacet* facet = ite.First(ev); ite.IsNotComplete(ev); facet = ite.Next(ev))
- {
- FW_CViewContext fc(ev, this, facet);
- DrawGrid(ev, fc, fGridShown);
- }
-
- ChangeHighlightState(ev, fGridShown ? kODFullHighlight : kODNoHighlight);
- }
-
- //----------------------------------------------------------------------------------------
- // CTableView::DoMenu
- //----------------------------------------------------------------------------------------
-
- FW_Handled CTableView::DoMenu(Environment* ev, const FW_CMenuEvent& theMenuEvent)
- {
- FW_Handled result = FW_kHandled;
- ODCommandID commandID = theMenuEvent.GetCommandID(ev);
-
- switch(commandID)
- {
- case cHideShowGrid:
- HideShowGrid(ev);
- break;
-
- default:
- result = FW_kNotHandled;
- break;
- }
-
- return result;
- }
-
- //---------------------------------------------------------------------------------------
- // CTableView::DoAdjustMenus
- //---------------------------------------------------------------------------------------
-
- FW_Handled CTableView::DoAdjustMenus(Environment* ev, FW_CMenuBar* menuBar, FW_Boolean hasMenuFocus, FW_Boolean isRoot)
- {
- FW_UNUSED(isRoot);
- if (hasMenuFocus)
- {
- FW_Boolean hasSelection = !fTableFrame->GetSelection(ev)->IsEmpty(ev);
- FW_Boolean canEmbedInCell = fGridShown && !hasSelection;
-
- menuBar->EnableAndToggleCommand(ev, cHideShowGrid, TRUE, fGridShown);
-
- // If an embedded part is selected, change Copy item to "Copy Part"
- FW_CString32 itemName;
- if (hasSelection)
- itemName = "Copy Part";
- else
- itemName = "Copy";
- menuBar->SetItemString(ev, kODCommandCopy, itemName);
-
- menuBar->EnableCommand(ev, kODCommandCopy, fGridShown && hasSelection);
- menuBar->EnableCommand(ev, kODCommandClear, fGridShown && hasSelection);
- menuBar->EnableCommand(ev, kODCommandCut, fGridShown && hasSelection);
-
- menuBar->EnableCommand(ev, kODCommandInsert, canEmbedInCell);
-
- // Check clipboard for pastable property
- menuBar->EnableCommand(ev, kODCommandPaste, canEmbedInCell && fTableFrame->HasPropertyOnClipboard(ev, kODPropContentFrame, NULL));
- menuBar->EnableCommand(ev, kODCommandPasteAs, canEmbedInCell && fTableFrame->HasPropertyOnClipboard(ev, kODPropContentFrame, NULL));
-
- // Because all my embedded frames are always selected I need to do my own enabling
- menuBar->EnableCommand(ev, kODCommandOpen, hasSelection);
- }
-
- return FW_kNotHandled;
- }
-
- //----------------------------------------------------------------------------------------
- // CTableView::PostCreateViewFromStream
- //----------------------------------------------------------------------------------------
- // Initialize back pointers
-
- void CTableView::PostCreateViewFromStream(Environment* ev)
- {
- fTableFrame = (CTableFrame*)GetFrame(ev);
- FW_ASSERT(fTableFrame != NULL);
-
- fTablePart = (CTablePart*)fTableFrame->GetPart(ev);
-
- fTableContent = fTablePart->GetTableContent(ev);
- FW_ASSERT(fTableContent != NULL);
-
- fTableContent->UpdateExtent(ev);
- }
-
- //----------------------------------------------------------------------------------------
- // CTableView::InternalTransformChanged
- //----------------------------------------------------------------------------------------
-
- void CTableView::InternalTransformChanged(Environment *ev)
- {
- // InternalTransformChanged can be called before fDrawPart as been initialized
- if (fTablePart != NULL)
- {
- FW_CFacetClipper facetClipper;
- facetClipper.Clip(ev, fTableFrame->GetPresentation(ev), NULL);
- }
- }
-